import http from '@/api';
import { PORT1, PORT2, PORT3 } from '@/api/config/servicePort';
import { PermissionInterface } from '@/api/interface/auth/permission';
import { PublicParams } from '@/api/interface/publicParams';

/**
 * @name 权限模块
 */

// 新增|编辑权限
export const permissionSave = (params: PermissionInterface.ReqSave) => {
  return http.post(PORT1 + `/permission/v1/save`, params);
};

// 修改状态
export const permissionUpdateStatus = (params: PublicParams.ReqStatus) => {
  return http.post(PORT1 + `/permission/v1/updateStatus`, params);
};

// 查询所有菜单权限(树结构)
export const permissionFindTreeMenuList = () => {
  return http.get<Menu.MenuOptions>(PORT1 + `/permission/v1/findTreeMenuList`);
};

// 查询所有权限(树结构)
export const permissionFindTreeList = () => {
  return http.get<Menu.MenuOptions>(PORT1 + `/permission/v1/findTreeList`);
};

// 查询平铺后的树结构(主要对树结构排序)
export const permissionFlattenTree = () => {
  return http.get<PermissionInterface.ResFlattenTree[]>(PORT1 + `/permission/v1/flattenTree`);
};
/**
 *根据角色id查询绑定的权限Id集合
 */
export const permissionFindListByRoleId = (params: PublicParams.ReqId) => {
  return http.get<Array<number>>(PORT1 + `/permission/v1/findListByRoleId`, params);
};

/**
 *根据角色id查询绑定的权限Id集合
 */
export const permissionPermissionIdsBindingRoleId = (params: PublicParams.ResBindingId) => {
  return http.post(PORT1 + `/permission/v1/permissionIdsBindingRoleId`, params);
};

// 查询所有权限
export const permissionFindListPermission = () => {
  return http.get<PermissionInterface.ReqSave[]>(PORT1 + `/permission/v1/findListPermission`);
};

// 删除权限
export const permissionDeleteById = (params: PublicParams.ReqId) => {
  return http.get(PORT1 + `/permission/v1/deleteById/${params.id}`, params);
};

// 根据父级id查询下一级
export const permissionFindByPid = (params: PublicParams.ReqId) => {
  return http.get(PORT1 + `/permission/v1/findByPid/${params.id}`);
};

// 获取后端api列表(树结构)
export const apiAuthScannerTree = () => {
  return http.get<PermissionInterface.ResFlattenTree[]>(PORT1 + `/apiScanner/v1/scan`);
};

// 获取后端api列表(树结构)
export const apiBasicScannerTree = () => {
  return http.get<PermissionInterface.ResFlattenTree[]>(PORT2 + `/apiScanner/v1/scan`);
};

// 获取后端api列表(树结构)
export const apiPersonnelScannerTree = () => {
  return http.get<PermissionInterface.ResFlattenTree[]>(PORT3 + `/apiScanner/v1/scan`);
};
